import { createApp } from 'vue'
import { createPinia } from 'pinia'

import App from './App.vue'
import router from './router'

/** 状态持久化插件 */
import piniaPersist from 'pinia-plugin-persist'

/** Element组件 */
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import zhCn from 'element-plus/es/locale/lang/zh-cn'
/** ****** */

const pinia = createPinia()
pinia.use(({ store }) => {
  /** setup语法糖自定义重置方法 */
  const initialState = JSON.parse(JSON.stringify(store.$state))
  store.$reset = () => {
    store.$patch(JSON.parse(JSON.stringify(initialState)))
  }

  /** setup语法糖自定义持久化方法 */
  piniaPersist({
    options: {
      persist: {
        enabled: true,
        strategies: [
          {
            key: 'use_store',
            storage: sessionStorage,
            paths: ['routerInclude', 'pageMenu', 'pageTabs']
          }
        ]
      }
    },
    store
  })
})

const app = createApp(App)
app.use(pinia)
app.use(router)
app.use(ElementPlus, { locale: zhCn, size: 'small' })
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component)
}

app.mount('#app')
